package com.tin.triper.UI;

import com.tin.triper.Constants;
import com.tin.triper.R;
import com.tin.triper.Data.LocationProvider;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MenuActivity extends Activity {
	/** Called when the activity is first created. */
	ImageView record;
	ImageView trips;
	ImageView settings;
	SharedPreferences prefs;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		prefs = getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE);

		record = (ImageView) findViewById(R.id.menu_record_button);
		trips = (ImageView) findViewById(R.id.menu_trips_button);
		settings = (ImageView) findViewById(R.id.menu_settings_button);

		record.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (prefs.getBoolean(Constants.IS_RECORDING, false)) {
					Intent intent = new Intent(MenuActivity.this,
							RecordActivity.class);
					intent.putExtra(Constants.ACTIVITY_MODE, -1);
					startActivity(intent);
				} else {
					Intent intent = new Intent(MenuActivity.this,
							TripSetupDialogActivity.class);
					startActivity(intent);
				}

			}
		});
		trips.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MenuActivity.this,
						TripListActivity.class);
				startActivity(intent);
			}
		});
		settings.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(MenuActivity.this,
						SettingsActivity.class);
				startActivity(intent);
			}
		});
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (prefs.getBoolean(Constants.IS_RECORDING, false))
			record.setImageResource(R.drawable.record_continue);
		else
			record.setImageResource(R.drawable.record_start);

	}

}